package org.apache.qpid.management.common.sasl;

import java.io.IOException;
import org.apache.harmony.javax.security.auth.callback.Callback;
import org.apache.harmony.javax.security.auth.callback.CallbackHandler;
import org.apache.harmony.javax.security.auth.callback.NameCallback;
import org.apache.harmony.javax.security.auth.callback.PasswordCallback;
import org.apache.harmony.javax.security.auth.callback.UnsupportedCallbackException;

public class UserPasswordCallbackHandler
  implements CallbackHandler
{
  private String user;
  private char[] pwchars;

  public UserPasswordCallbackHandler(String paramString1, String paramString2)
  {
    this.user = paramString1;
    this.pwchars = paramString2.toCharArray();
  }

  public void handle(Callback[] paramArrayOfCallback)
    throws IOException, UnsupportedCallbackException
  {
    for (int i = 0; i < paramArrayOfCallback.length; i++)
    {
      Object localObject;
      if ((paramArrayOfCallback[i] instanceof NameCallback))
      {
        localObject = (NameCallback)paramArrayOfCallback[i];
        ((NameCallback)localObject).setName(this.user);
      }
      else if ((paramArrayOfCallback[i] instanceof PasswordCallback))
      {
        localObject = (PasswordCallback)paramArrayOfCallback[i];
        ((PasswordCallback)localObject).setPassword(this.pwchars);
      }
      else
      {
        throw new UnsupportedCallbackException(paramArrayOfCallback[i]);
      }
    }
  }

  private void clearPassword()
  {
    if (this.pwchars != null)
    {
      for (int i = 0; i < this.pwchars.length; i++)
        this.pwchars[i] = '\000';
      this.pwchars = null;
    }
  }

  protected void finalize()
  {
    clearPassword();
  }
}

/* Location:           D:\hygieia\userclient\common\libs\easemobchat_2.1.8.jar
 * Qualified Name:     org.apache.qpid.management.common.sasl.UserPasswordCallbackHandler
 * JD-Core Version:    0.6.1
 */